# from moviepy.editor import VideoFileClip
# from PIL import Image
# import os
# video = r'E:\2019PythonProject\PyQt5_Opencv\data\video\20200824_154458.h264'
# clip = VideoFileClip(video)
# i = 0
# output = 'C:\\Users\\wangj\\Desktop\\新驿苫布'
# if not os.path.exists(output):
#     os.mkdir(output)
# for frame in clip.iter_frames():
#     im = Image.fromarray(frame)
#     im.save(output+"\\xinyi%07d.bmp" % i)
#     i = i+1
#     print("save to = {}".format(output))


# -*- coding:utf8 -*-
import cv2
import os
import shutil

def VideoExtract(filename, save_path,save_name_label,count=600):
    '''
    :param filename: 视频文件路径
    :param count: 保存图片的帧率间隔
    :return:
    '''
    videoCapture = cv2.VideoCapture(filename)
    i = 0
    j = 0
    while True:
        success, frame = videoCapture.read()
        i += 1
        if (i % count == 0):
            # 保存图片
            j += 1
            savedname = save_path + '\\' + save_name_label + str(j) + '.bmp'
            cv2.imwrite(savedname, frame)
            print('image of %s is saved' % (savedname))
        if not success:
            break

if __name__=='__main__':
    filename = r'C:\Users\wangj\Downloads\1600329395.h264'
    save_path = r'C:\Users\wangj\Desktop\tmp'
    save_name_label = 'xinyi_2020_0915_08_'
    VideoExtract(filename,save_path,save_name_label,count=50)